from django.contrib.auth.models import User

from django.http import HttpResponse
from django.shortcuts import render_to_response
from models import UploadArticleForm
#def handle_uploaded_file(f):
#    destination = open('some/file/name.txt', 'wb+')
#    for chunk in f.chunks():
#        destination.write(chunk)
#    destination.close()
 #  form=UploadFileForm()
 #   form.title = request.get("title")
 #   file = request.get("img")
 #   form.file = db.Blob(file)
 #   form.put()
 #   return render_to_response('upload_form.html', {'form':form})
def index(request):
    form=UploadArticleForm()
    user=request.user
    return render_to_response('add_article.html', {'form':form,'user':user})

def save(request):
    if request.method == 'POST': 
#        save_article(request.FILES,user)

        return HttpResponse("Article saved.")
def publish(request):
    if request.method == 'POST': 
        #        publish_article(request.FILES,user)
        return  redirect('/')
#        return HttpResponse("Article published.")
    return  redirect('/')
# def handle_uploaded_file(f,caption):
#     greeting=Greeting()
#     greeting.avatar=db.Blob(f)
#     greeting.caption=caption
#     greeting.put()
#     for chunk in f.chunks():
#         destination.write(chunk)
#     destination.close()
# def upload(request):
#     if request.method == 'POST': 
#         handle_uploaded_file(request.FILES['img'],0)
#         return render_to_response('success.html',{})
#     return render_to_response('upload.html',{})

#def handle_upload(request):
#    return #render_to_response('success.html',{})
    
